import { RouteLocationNormalizedLoaded, Router, useRoute, useRouter } from 'vue-router';
import type { ComponentInternalInstance } from "vue";
import { getCurrentInstance } from "vue";
import System from '@/common/System';

/*系统api规则*/
interface GetAppType {
    Router: "Router",
    Route: "Route",
    System: "System",
    Vm: "Vm"
}
export function getApp<K extends keyof GetAppType>(keys?: K[]) {

    let Router: Router | null = null;
    let Route: RouteLocationNormalizedLoaded | null = null;
    let Vm: ComponentInternalInstance | null = null;

    if (keys)
    for (let i: number = 0; i < keys.length; i ++) {
        switch (keys[i]) {
            case "Router":
                Router = useRouter();
                break;
            case "Route":
                Route = useRoute();
                break;
            case "Vm":
                Vm = getCurrentInstance()!;
                break;
        }
    }

    return {
        Router,
        Route,
        System,
        Vm
    }
}
